package com.njlime.cms.repository.sys;

import com.njlime.cms.entities.Label;
import com.njlime.cms.entities.LiveConfig;
import com.njlime.core.base.repository.impl.BaseDaoImpl;
import com.njlime.core.helper.PageBean;
import com.njlime.core.utils.StringUtil;
import com.njlime.sys.security.util.UserUtils;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Dean on 2017/10/13.
 */
@Repository
public class LiveConfigDaoImpl extends BaseDaoImpl<LiveConfig> {

    /**
     * 获取
     *
     * @param unit_id
     * @return
     */
    public LiveConfig getCurConfig(int unit_id) {
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select * from t_live_config where unit_id = ? and is_del = 0 ");
        arrList.add(unit_id);
        return findOne(sb.toString(),arrList);
    }

    /**
     * 删除
     *
     * @param unit_id
     * @return
     */
    public int delCurConfig(int unit_id) {
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("update t_live_config set is_del = 1 where unit_id = ? and is_del = 0 ");
        arrList.add(unit_id);
        return updateJdbc(sb.toString(),arrList);
    }

    public void edit(LiveConfig info){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("update t_live_config set userid = ?,secret = ? where unit_id = ? and is_del = 0 ");
        arrList.add(info.getUserid());
        arrList.add(info.getSecret());
        arrList.add(info.getUnit_id());
          updateJdbc(sb.toString(),arrList);
    }
}
